# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity_study_code
File Name: 将validate中数据替换.py
Author: kij
Create Date: 2021/8/27
-------------------------------------------------
"""
import os
import re
import arrayjm

_0x4aee = ['avai\x20false', '请先输入各项信息！', 'test', 'getFullYear', 'toString', 'substring', 'length', 'getMonth', 'getDate', 'charAt', 'charCodeAt', '请输入验证码', '#fpdm', 'val', '#fphm', '#kprq', 'YYYYMMDD', '#kjje', '#yzm_img', 'attr', 'src', 'images/code.png', '#yzm_unuse_img', '#context', 'text', '开具金额(不含税)：', '#fpdmjy', '请输入发票代码', 'removeClass', 'addClass', 'tip_common', '#fphmjy', '请输入发票号码', '#kprqjy', '请输入开票日期', '#kjjejy', '请输入开具金额', '#yzm', 'css', 'color', '#999999', '#yzminfo', '#checkfp', 'hide', '#uncheckfp', 'show', 'focus', 'parent', 'pricode', 'clearB', 'trim', 'YYMMDD', 'log'];

def get_indexfuncjs():
    """
    获取eab23js文件
    """
    # 读文件
    # 1.获取当前文件 读文件操作.py 的路径
    abs = os.path.abspath(__file__)
    # 找到上级目录 dirname
    path = os.path.dirname(abs)
    base_dir = os.path.dirname(os.path.abspath(__file__))
    # 路径拼接 ()可以跟多了路径
    file_path = os.path.join(base_dir, "validate.html")
    # 2.判断文件是否存在
    if not os.path.exists(file_path):
        print("文件夹不存在就创建")
    # os.makedirs(file_path)
    else:
        # 字节读取
        file_object = open(file_path, mode='rb')
        data = file_object.read()
        file_object.close()
        text = data.decode('utf-8')
        # 文本读取
        file_text = open(file_path, mode='rt', encoding='utf-8')
        file_message = file_text.read()
        file_text.close()
    return file_message



if __name__ == "__main__":
    my_jiemishuzu_dict = {}

    for item in range(len(_0x4aee)):
        my_jiemishuzu_dict[f"""_0x1f4f('{hex(item)}')"""] = _0x4aee[item]
    # print(my_jiemishuzu_dict)
    js_message = get_indexfuncjs()
    pattern = '_0x1f4f\(\'0x.*?\'\)'

    list_t = re.findall(pattern, js_message)

    newstr = js_message
    for key, value in my_jiemishuzu_dict.items():
        newstr = newstr.replace(f"""{key}""", f"'{value}'")
    print(newstr)
